<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <title>jQuery Ajax</title>
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
</head>
<body>
<div>
    请输入你的学号：<input type="text" id="submitter_id"/>
    请输入你的认证码：<input type="text" id="submitter_code"/>
</div>
<div>
    请输入同住人1的学号：<input type="text" id="student1_id"/>
    请输入同住人1认证码：<input type="text" id="student1_code"/>
</div>

<div>
    请输入同住人2的学号：<input type="text" id="student2_id"/>
    请输入同住人2认证码：<input type="text" id="student2_code"/>
</div>

<div>
    请输入同住人3的学号：<input type="text" id="student3_id"/>
    请输入同住人3认证码：<input type="text" id="student3_code"/>
</div>

<div>
    请选择目标楼号
    <select id="buildingName">
        <option value="五号楼">五号楼</option>
        <option value="八号楼">八号楼</option>
        <option value="十三号楼">十三号楼</option>
    </select>
</div>

<div>
    <button id="btn1">提交</button>
</div>


<div id="result">

</div>
</body>
<script type="text/javascript">
    $(document).ready(function () {
        $("#btn1").click(function () {
            let submitter_id = $("#submitter_id").val();
            let submitter_code = $("#submitter_code").val();
            let building_name = $("#buildingName").val();
            let followers_id = [], followers_code = [];
            for (let i = 1; i <= 3; ++i) {
                let follower_id = $("#student" + i + "_id").val();
                let follower_code = $("#student" + i + "_code").val();
                followers_id[i - 1] = follower_id;
                followers_code[i - 1] = follower_code;
                console.log(follower_id + " : " + follower_code);
            }
            let token = localStorage.getItem("token");
            console.log(token)
            $.ajax({
                type: 'post',
                url: "http://59.110.168.33:8083/dorm/choose",
                // url: 'http://localhost:8083/dorm/choose',
                contentType: 'application/x-www-form-urlencoded',
                dataType: 'json',
                data: {
                    studentNos: followers_id,
                    codes: followers_code,
                    submitterId: submitter_id,
                    submitterCode: submitter_code,
                    buildingName: building_name
                },
                beforeSend: function (request) {
                    request.setRequestHeader("token", token);
                },
                success: function (data) {
                    console.log(data)
                    $("#result").text("ok")
                },
                error: function (data) {
                    console.log(data)
                    $("#result").text("请先登录!");
                }
            });
        });
    });
</script>
</html>